//
//  WBViewController.swift
//  PersonalWeibo
//
//  Created by Liuwx on 2017/9/16.
//  Copyright © 2017年 Liuwx. All rights reserved.
//

import UIKit

class WBNavigationViewController: UINavigationController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        //隐藏默认的navigationBar
        navigationBar.isHidden = true
    }
    
    
    
    
//重写push的方法，所有的push动作都调用这个方法
    //viewController 是push的controller ，设置他的返回按钮
    override func pushViewController(_ viewController: UIViewController, animated: Bool) {
        //如果不是栈地控制器材需要隐藏，根控制器不需要隐藏
        if childViewControllers.count > 0 {
            // 隐藏底部的tabar

            viewController.hidesBottomBarWhenPushed = true
        
            // 判断控制器的类型
            if let vc = viewController as? WBBaseViewController {
                var title = "返回"
                //判断控制器的级数，只有一个控制的时候，显示栈低控制器的名字
                if childViewControllers.count == 1 {
                    title = childViewControllers.first?.title ?? "返回"
                }
                vc.navItem.leftBarButtonItem = UIBarButtonItem(title: title, tagret: self, action: #selector(popToPrarent), isBack: true)
            }
        }
        
        
        
        super.pushViewController(viewController, animated: true)
        
    }
 
    //返回到上一级控制
    @objc private func popToPrarent() {
        popViewController(animated: true)
    }

}
